<!-- 技术分析 -->
<template>

	<ListLayout>

		<Card>
			<template #head>
				技术分析信息
			</template>
			<template #body>
				<evan-form :model="formData" ref="form">
					<evan-form-item label="难易程度">
						<ItemRow v-model="formData.difficulty" dicKey="difficulty"></ItemRow>
					</evan-form-item>
					<evan-form-item label="当前技术风险" prop="technicalRisk">
						<u-input v-model="formData.technicalRisk" type="textarea" input-align="right"></u-input>
					</evan-form-item>
					<evan-form-item label="建议解决方案" prop="solution">
						<u-input v-model="formData.solution" type="textarea" input-align="right"></u-input>
					</evan-form-item>
					<evan-form-item label="实施形式" prop="applyType">
						<ItemRow v-model="formData.applyType" dicKey="implementation_form"></ItemRow>
					</evan-form-item>
					<evan-form-item label="评估备注">
						<u-input v-model="formData.remark" type="textarea" input-align="right"></u-input>
					</evan-form-item>

				</evan-form>
			</template>
		</Card>

		<AttachmentCard ref="AttachmentCard"></AttachmentCard>


		<template #footer>
			<HButtonGroup @leftClick="leftClick" @rightClick="rightClick">
				<template #left>
					取消
				</template>
				<template #right>
					提交
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>

</template>
<script>
	import Card from '@/components/card/components/cardBaseWrapper.vue'
	import ListLayout from '@/components/layout/listLayout.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import ItemRow from '@/components/arrow/itemArrow.vue'
	import ProjectApi from '@/apis/project.js'
	import AttachmentCard from '@/components/card/attachment.vue'
	import PagesDemandRouterConfig from '@/pagesDemand/routerConfig.js'
	import { attachmentFormatter } from '@/common/submitFormatter.js'
	export default {
		components: {
			Card,
			ListLayout,
			HButtonGroup,
			ItemRow,
			AttachmentCard
		},

		data() {
			return {
				formData: {
					// 难易程度
					difficulty: 1,
					// 技术风险
					technicalRisk: '',
					// 建议解决方案
					solution: '',
					// 实施形式
					applyType: '',
					// 备注
					remark: '',
					// 预估工时 【天】
					workingHours: '',
					// 附件
					enclosure: '',
				},
				rules: {
					technicalRisk: [{
						required: true,
						message: '当前技术风险不能为空',
					}],
					solution: [{
						required: true,
						message: '建议解决方案不能为空',
					}],
					applyType: [{
						required: true,
						message: '请选择实施形式',
					}],
				},
				routerParams: {
					itemCode: ''
				}

			}
		},
		onLoad(query) {
			let { itemCode } = query
			this.routerParams.itemCode = itemCode
			this.initData()

		},
		onReady() {
			this.$nextTick(() => {
				this.$refs.form.setRules(this.rules)

			})
		},
		methods: {
			async initData() {

				let res = await ProjectApi.Demand.GetDemandDetail(this.routerParams.itemCode)
				const data = res.body || {}
				if (data.technicalAnalysis) {
					this.formData = data.technicalAnalysis;
				}

			},

			leftClick() {
				wx.navigateBack()
			},
			rightClick() {
				let self = this;
				self.$refs.form.validate(async (valid) => {

					if (valid) {
						let attachment = this.$refs.AttachmentCard.$data.attachment
						self.formData.enclosure = attachmentFormatter(attachment)
						self.formData.itemCode = self.routerParams.itemCode

						console.log(attachment, self.formData);
						await ProjectApi.Demand.SubmitTechnicalAnalysis(self.formData);
						wx.showToast({
							title: '提交成功',
							icon: 'success',
							complete() {
								wx.redirectTo({
									url: PagesDemandRouterConfig.Demand
								})
							}
						})


					}
				});
			},

		}
	}
</script>
